package oa.hleast.xswl.service.questionnaire.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import oa.hleast.xswl.mapper.questionnaire.QmsProblemMapper;
import oa.hleast.xswl.pojo.domain.questionnaire.QmsAnswer;
import oa.hleast.xswl.pojo.domain.questionnaire.QmsProblem;
import oa.hleast.xswl.pojo.form.questionnaire.QmsAnswerForm;
import oa.hleast.xswl.service.questionnaire.QmsProblemService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: 302
 * @date: 2021-07-19 18:42:18
 * @description: 问卷问题表(QmsProblem)接口实现
 */
@Service("qmsProblemService")
public class QmsProblemServiceImpl extends ServiceImpl<QmsProblemMapper, QmsProblem> implements QmsProblemService {
    int alphabetically = 65;

    @Override
    public List<QmsAnswer> saveAnswer(List<QmsAnswerForm> qmsAnswerVoList, Long problemId, Long questionnaireId){
        List<QmsAnswer> saveList = new ArrayList<>();
        for (int i = 0; i < qmsAnswerVoList.size(); i++)
        {
            QmsAnswer qmsAnswer = new QmsAnswer();
            BeanUtil.copyProperties(qmsAnswerVoList.get(i),qmsAnswer,"id");
            qmsAnswer.setAnswerNumber((char)(i + alphabetically));
            qmsAnswer.setProblemId(problemId);
            qmsAnswer.setQuestionnaireId(questionnaireId);
            saveList.add(qmsAnswer);
        }
        return saveList;
    }

    @Override
    public List<QmsAnswer> updateAnswer(List<QmsAnswerForm> qmsAnswerVoList, Long problemId, Long questionnaireId)
    {
        List<QmsAnswer> updateList = new ArrayList<>();
        for (int i = 0; i < qmsAnswerVoList.size(); i++)
        {
            QmsAnswer qmsAnswer = new QmsAnswer();
            BeanUtil.copyProperties(qmsAnswerVoList.get(i),qmsAnswer);
            qmsAnswer.setAnswerNumber((char)(i + alphabetically));
            qmsAnswer.setProblemId(problemId);
            qmsAnswer.setQuestionnaireId(questionnaireId);
            updateList.add(qmsAnswer);
        }
        return  updateList;
    }


}
